package com.ynjt.view;


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;

public class ChatFrame implements ActionListener {

    JTextArea inputText, outputText;

    public ChatFrame() {
        JFrame frame = new JFrame();
        inputText = new JTextArea(10, 25);
        outputText = new JTextArea(15, 25);

        JButton button = new JButton("发送");
        button.addActionListener(this);

        JPanel panel = new JPanel();
        panel.add(inputText);
        panel.setBackground(Color.lightGray);

        frame.getContentPane().add(BorderLayout.NORTH, outputText);
        frame.getContentPane().add(BorderLayout.CENTER, panel);
        frame.getContentPane().add(BorderLayout.SOUTH, button);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 400);
        frame.setVisible(true);


    }


    public void actionPerformed(ActionEvent event) {
        Date time = new Date();
        String t = String.format("2017/%tB/%<td %<tr", time);
        if (inputText.getText().length() != 0) {
            outputText.append("[我]" + t + "\n" + inputText.getText() + "\n");
        }
        inputText.setText("");
    }


}
